﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lidgren.Network;
using Lidgren.Network.Xna;
using Krypton.Lights;
using Microsoft.Xna.Framework.Graphics;

namespace SharedLib.Engine
{
    public class Light : Entity
    {
        public byte  R { get; set; }
        public byte  G { get; set; }
        public byte  B { get; set; }
        public float Intensity { get; set; }
        public Int16 Range { get; set; }
        public float Fov { get; set; }

        public Light2D KryptonLight { get; set; }

        public Light()
        {
            Type = EntityType.Light;
        }

        public override void WriteData(NetOutgoingMessage outmsg)
        {
            base.WriteData(outmsg);
            outmsg.Write(this.ID);
            outmsg.Write(this.Name);
            outmsg.Write(this.Position);
            outmsg.Write(this.Rotation);
            outmsg.Write(this.R);
            outmsg.Write(this.G);
            outmsg.Write(this.B);
            outmsg.Write(this.Intensity);
            outmsg.Write(this.Range);
            outmsg.Write(this.Fov);
        }

        public override void ReadData(NetIncomingMessage _msgBuffer)
        {
            this.ID = _msgBuffer.ReadInt64();
            this.Name = _msgBuffer.ReadString();
            this.Position = _msgBuffer.ReadVector2();
            this.Rotation = _msgBuffer.ReadFloat();
            this.R = _msgBuffer.ReadByte();
            this.G = _msgBuffer.ReadByte();
            this.B = _msgBuffer.ReadByte();
            this.Intensity = _msgBuffer.ReadFloat();
            this.Range = _msgBuffer.ReadInt16();
            this.Fov = _msgBuffer.ReadFloat();

            KryptonLight = new Light2D()
            {

                Texture = (Texture2D)SharedLib.Network.Client.ClientProperties.Instance.ObjectsBox["lightTexture"],
                Range = this.Range,
                Color = new Microsoft.Xna.Framework.Color(R,G,B),
                Intensity = Intensity,
                Angle = Rotation,
                Fov = Fov,

                X = Position.X,
                Y = Position.Y
            };
        }

    }
}
